import 'package:flutter/material.dart';
import 'package:flutter_app/utils/http.dart';
import 'package:flutter_app/widget/page_route_anim.dart';
import 'package:flutter_app/views/cardDetail.dart';

class WarningCardList extends StatefulWidget {
  @override
  _WarningCardList createState() => _WarningCardList();
}

class _WarningCardList extends State<WarningCardList> {
  @override
  void initState(){
    super.initState();
    getList();
  }
  // 黑色 333   文字666    中间放按钮（前往处理） 按钮统一

  List warningData = [];
  //  获取列表
  getList() async{
    ResultData list = await HttpRequest.post('/webauth/alarm/listAlarm', {
      'pageNum':1,
      'pageSize':20,
      'dealType':'1' // 未处理
    });
    // print(list);
    setState(() =>
    warningData = list.data['list']
    );
  }

  setItem(index){
    if(warningData.length == 0){
      return Container();
    }
    return Container(
        margin:EdgeInsets.only(left:15, right: 15),
        padding:EdgeInsets.only(top:15, bottom: 5),
        child:Column(
          children: [
            Container(
              margin:EdgeInsets.only(bottom: 15),
              child: Row(
                children: [
                  Text(warningData[index]["alarmTypeName"],style: TextStyle(fontWeight: FontWeight.w700))
                ],
              ),
            ),
            Container(
              margin:EdgeInsets.only(bottom: 5),
              child: Row(
                children: [
                  Text('抓拍时间:'+ warningData[index]["acquisitionTime"])
                ],
              ),
            ),
            Container(
              margin:EdgeInsets.only(bottom: 5),
              child: Row(
                children: [
                  Text('抓拍地点:'+ warningData[index]["acquisitionPlace"])
                ],
              ),
            ),
            Container(
              child: Row(
                children: [
                  Text('设备名称:'+ warningData[index]["deviceName"])
                ],
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children:[Text('前往处理',style: TextStyle(color: Colors.blueAccent))],
            ),
          ],
        )
    );
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      child: ListView.separated(
        padding: EdgeInsets.only(top:5, bottom: 5),
        itemCount:warningData.length,
        itemBuilder: (context, index) {
          return InkWell(
            onTap: () {
              Navigator.of(context).push(SlidingAroundRoute(CardDetail(id:warningData[index]["id"])));
            },
            child: setItem(index)
          );
        },
        separatorBuilder: (context, index) {
          return Divider(
            height: .5,
            indent: 15,
            endIndent: 15,
            color: Color(0xD4D4D4FC),
          );
        },
      ),
    );
  }
}